from one import cover_width_func, cover_width_negative_func, cover_width_positive_func
import math
from sympy import symbols, Eq, solve


def from_left():
    def from_x_to_depth(center_depth, x, a):
        return center_depth + (2 * 1852 - x) * math.tan(a)

    a = math.radians(1.5)
    center_depth = 110
    result = []
    rate = 0.1
    x = symbols("x")
    depth = from_x_to_depth(center_depth, x, a)
    equation = Eq(cover_width_negative_func(depth, a), x)
    solution = solve(equation, x)
    x_1 = solution[0]
    result.append(x_1)
    x_2 = 0
    while (
        x_2 + cover_width_positive_func(from_x_to_depth(center_depth, x_2, a), a)
    ) < (4 * 1852):
        depth_1 = from_x_to_depth(center_depth, x_1, a)
        left_position = (
            x_1
            + cover_width_positive_func(depth_1, a)
            - cover_width_func(depth_1, a) * rate
        )

        equation = Eq(
            cover_width_negative_func(from_x_to_depth(center_depth, x, a), a),
            x - left_position,
        )
        solution = solve(equation, x)
        x_2 = solution[0]
        result.append(x_2)
        x_1 = x_2
    print(result)
    # for i in result:
    #     print(i - 2 * 1852, end=" ")
    print("len: ", len(result))


def from_right():
    def from_x_to_depth(center_depth, x, a):
        return center_depth - (2 * 1852 - x) * math.tan(a)

    center_depth = 110
    rate = 0.1
    a = math.radians(1.5)
    result = []
    x = symbols("x")
    depth = from_x_to_depth(center_depth, x, a)
    equation = Eq(cover_width_positive_func(depth, a), x)
    solution = solve(equation, x)
    x_1 = solution[0]
    result.append(x_1)
    x_2 = 0
    while (
        x_2 + cover_width_negative_func(from_x_to_depth(center_depth, x_2, a), a)
    ) < (4 * 1852):
        depth_1 = from_x_to_depth(center_depth, x_1, a)
        right_position = (
            x_1
            + cover_width_negative_func(depth_1, a)
            - cover_width_func(depth_1, a) * rate
        )

        equation = Eq(
            cover_width_positive_func(from_x_to_depth(center_depth, x, a), a),
            x - right_position,
        )
        solution = solve(equation, x)
        x_2 = solution[0]
        result.append(x_2)
        x_1 = x_2
    print(result)
    print("len:", len(result))


if __name__ == "__main__":
    from_left()
